﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Windows.Forms;
using XmlAppliction;

namespace TJXAppliction
{
    static class Program
    {

        

        public static string ConfigXMLPath = Application.StartupPath + "\\config.xml";//配置文件路径 
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {

            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();
            DevExpress.Skins.SkinManager.EnableFormSkins();


            //增加可以直接登录的代码
            if (args.Length == 3)
            {
                Globes.m_UserID = args[0];
                Globes.m_UserPassword = args[1];
                Globes.m_DatabaseName = args[2];
            }
             
            XmlAppliction.Doman.ConfigUser configUser;//配置列表
            //string str= DBUtility.DESEncrypt.Encrypt("Data Source=TOHZJ;Persist Security Info=True;User ID=hzjuser;password=hzjuser");
            string fold;  
            //如果配置文件不存在
            if (!File.Exists(Program.ConfigXMLPath))
            {
                DateTime befoDate = DateTime.Now;
                DateTime nowDate = DateTime.Now;
                try
                {
                    XMLHelper.writeFirstconfigXML(string.Format("{0}-{1}-{2}", befoDate.Year, befoDate.Month, befoDate.Day), string.Format("{0}-{1}-{2}", nowDate.Year, nowDate.Month, nowDate.Day), Program.ConfigXMLPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            try
            {
                //检查配置文件夹是否存在
                configUser = new XmlAppliction.Doman.ConfigUser(Program.ConfigXMLPath);
                fold = Application.StartupPath + "\\CreateXMLs";
                if (configUser.SaveXMLPath.Trim() == "")
                {
                    configUser.SaveXMLPath = fold;
                }
                if (!Directory.Exists(fold))
                {
                    Directory.CreateDirectory(fold);
                }
                fold = Application.StartupPath + "\\muban";
                if (configUser.WordMubanPath.Trim() == "")
                {
                    configUser.WordMubanPath = fold;
                }
                if (!Directory.Exists(fold))
                {
                    Directory.CreateDirectory(fold);
                }
                configUser.SaveWordPath = "c:\\";
                configUser.saveConfigXML();//保存信息  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DBMgr.DbHelperOra.connectionString = configUser.ConnectionString; 

            
            //DBMgr.DbHelperOra.connectionString=
            Application.EnableVisualStyles(); 
            Application.SetCompatibleTextRenderingDefault(false);
            //try
            //{
            //    bool loginstatue=XmlAppliction.Globes.DoLogin();
            //    //验证权限
                
            //    if(loginstatue)
            //    {
            //        if (!XmlAppliction.PublicClass.CheckUser.M_ValidateIP("业务信息显示", XmlAppliction.PublicClass.CheckUser.GetLocalIP()))
            //        {
                    //    MessageBox.Show("对不起，你当前运行的位置不在许可范围内", "提示");
                    //}
                    //else
                    //{ 
                        Application.Run(new XmlAppliction.Form1());
            //        }
            //    }
            //}
            //catch(Exception ex)
            //{
            //    Console.WriteLine (ex.Message);
            //}
        }



    }
}
